﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using ECCIT;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Configuration;

public partial class GateService_CommentVideoInterface : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "text/xml";
        Response.ContentEncoding = Encoding.UTF8;

        string output = string.Empty;
        try
        {
            ResultInfo valRes = ValidateArguments();

            if (valRes.Result)
            {
                string sLangID = Request.Params["lang"];
                int langID = (string.IsNullOrEmpty(sLangID)) ? 2052 : int.Parse(sLangID);
                string sCommentID = Request.Params["commentid"];
                int commentID = (string.IsNullOrEmpty(sCommentID)) ? 0 : int.Parse(sCommentID);
                EventsCommentBLL bll = new EventsCommentBLL(langID);
                EventsCommentModel model = bll.selEvent(commentID);
                if (commentID < 0 || model == null) throw new Exception("No video.");
                output = output = string.Format("<video name=\"{0}\" url=\"{1}\" imgUrl=\"{2}\"></video>", 
                    model.VideoName, ConfigCacheManager.FilePath.UploadFrontMediaPath.VirtualPath + "/" + model.VideoName,
                    ConfigCacheManager.FilePath.UploadVideoCutPath.VirtualPath + "/" + model.VideoName.Replace(".flv", ".jpg"));
            }
        }
        catch (Exception ex)
        {
            output = "<files value=\"false\"></files>";
        }

        Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + output);
    }

    private ResultInfo ValidateArguments()
    {
        ResultInfo result = new ResultInfo(false);
        string sLangID = Request.Params["lang"];
        if (string.IsNullOrEmpty(sLangID)) return result;

        int langID;
        bool b = int.TryParse(sLangID, out langID);
        if (!b) return result;
        if (langID != 2052 && langID != 1033) return result;

        result.Result = true;
        return result;
    }
}